home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / HASWIN / HASWIN3 / _files / _haswin / TASK._c < prev    next >
Text File  |  1991-05-27  |  5KB  |  142 lines

  1. /* > $.CLIB.HASWIN.C.task
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      task control routines.  The comments in this code talk about a
  21.  *      linked list of tasks maintained by HASWIN to ease inter-process
  22.  *      communications.  This has become unnecessary since I don't do
  23.  *      inter-process communications properly in this release of HASWIN.
  24.  *      It all will be added later!
  25.  */
  26. #include "includes.h"
  27.  
  28. int haswin_gettaskid() {
  29.         if (!(haswin_flags & HASWIN_FLAGS_STARTED))
  30.                 return(HASWIN_UNKNOWN);
  31.         return(haswin_taskid);
  32. }
  33.  
  34. char *haswin_gettaskname() {
  35.         if (!(haswin_flags & HASWIN_FLAGS_STARTED))
  36.                 return((char *)0);
  37.         return(haswin_taskname);
  38. }
  39.  
  40. void haswin_taskclosedown() {
  41.  
  42.         _kernel_swi_regs  regs;
  43.  
  44.         /* close the WIMP down */
  45.         if (haswin_flags & HASWIN_FLAGS_STARTED) {
  46.                 if (haswin_taskid != HASWIN_UNKNOWN) {
  47.                         regs.r[0] = haswin_taskid;
  48.                         regs.r[1] = 'T' + ('A'<<8) + ('S'<<16) + ('K'<<24);
  49.                 } else
  50.                         regs.r[0] = regs.r[1] = 0;
  51.                 haswin_swi(HASWIN_Closedown , ®s);
  52.                 haswin_flags &= ~HASWIN_FLAGS_STARTED;
  53.         }
  54. }
  55.  
  56. /*
  57.  *      initialise the window managment system.
  58.  *      First we start the WIMP and then generate the linked list of
  59.  *      active tasks.  This is maintained by the haswin_poll() routine
  60.  *      as tasks enter and leave the system.  The first task in the list
  61.  *      is ourselves.
  62.  */     
  63. int haswin_taskinitialise(char *name) {
  64.  
  65.         _kernel_swi_regs  regs;
  66.  
  67. /* start the HASWIN WIMP */
  68.         regs.r[0] = 200;    /* we require WIMP version 2.00 or later */
  69.         if ((!name) || (name[0] == 0)) {
  70.                 regs.r[1] = 0;
  71.                 regs.r[2] = 0;
  72.                 if (!haswin_swi(HASWIN_Initialise, ®s))
  73.                         return(HASWIN_FALSE);
  74.                 haswin_taskid = HASWIN_UNKNOWN;
  75.                 strncpy(haswin_taskname, "Not a Task", TASK_MAXNAME);
  76.         } else {
  77.                 regs.r[1] = 'T' + ('A'<<8) + ('S'<<16) + ('K'<<24);
  78.                 regs.r[2] = (int)name;
  79.                 if (!haswin_swi(HASWIN_Initialise, ®s))
  80.                         return(HASWIN_FALSE);
  81.                 haswin_taskid = regs.r[1];
  82.                 strncpy(haswin_taskname, name, TASK_MAXNAME);
  83.         }
  84.         haswin_version = regs.r[0];
  85.         return(haswin_version);
  86. }
  87.  
  88. /*
  89.  *      Given a window handle find the task name of the owner of the window.
  90.  *      return NULL on an error.  We issue a TaskNameRq message to the Task
  91.  *      Manager and then poll until we get a reply.  haswin_poll() places
  92.  *      the reply into the string "haswin_tasknameis" for us, which we then
  93.  *      return.
  94.  */
  95. char *haswin_findtasknamewin(int win) {
  96.         buffer                  buff;
  97.         _kernel_swi_regs        regs;
  98.  
  99.         if (!win)
  100.                 return(0);
  101.         buff.i[0] = 24;
  102.         buff.i[1] = 0;
  103.         buff.i[2] = 0;
  104.         buff.i[3] = 0;
  105.         buff.i[4] = MESSAGE_TaskNameRq;
  106.         buff.i[5] = win;
  107.         regs.r[0] = HASWIN_POLL_Message_Rec;
  108.         regs.r[1] = (int)&buff;
  109.         regs.r[2] = win;
  110.         regs.r[3] = -1;
  111.         haswin_swi(HASWIN_Send_message, ®s);
  112.         haswin_flags |= HASWIN_FLAGS_TASKIS;
  113.         while (haswin_flags & HASWIN_FLAGS_TASKIS)
  114.                 haswin_poll();
  115.         return(haswin_tasknameis);
  116. }
  117.  
  118. /*
  119.  *      Given a window handle find the task id of the owner of the window.
  120.  *      return HASWIN_UNKNOWN on an error.  We issue a dummy message to
  121.  *      the Task Manager to get the taskid back.
  122.  */
  123. int haswin_findtaskidwin(int win) {
  124.         buffer                  buff;
  125.         _kernel_swi_regs        regs;
  126.  
  127.         if (!win)
  128.                 return(HASWIN_UNKNOWN);
  129.         buff.i[0] = 20;
  130.         buff.i[1] = 0;
  131.         buff.i[2] = 0;
  132.         buff.i[3] = 0;
  133.         buff.i[4] = 0;
  134.         regs.r[0] = HASWIN_POLL_Message_Ack;
  135.         regs.r[1] = (int)&buff;
  136.         regs.r[2] = win;
  137.         regs.r[3] = -1;
  138.         haswin_swi(HASWIN_Send_message, ®s);
  139.         return(regs.r[2]);
  140. }
  141.  
  142.